package com.fc.v2.config.multiSource;

import com.fc.v2.model.auto.SysTenant;
import com.fc.v2.service.auto.ISysTenantService;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * 初始化动态数据源
 * @Classname DynamicDataSourceInit
 * @Date 2022/2/12 3:35
 * @Created by 87766867@qq.com
 */
@Configuration
public class DynamicDataSourceInit {
    @Resource
    private ISysTenantService iSysTenantService;

    @PostConstruct
    public void initDataSource() {
        System.out.println("=====初始化动态数据源=====");
        List<SysTenant> sysTenants=iSysTenantService.list();
        sysTenants.forEach(item->{
            DynamicDataSource.setDataSourceMap(item);
        });
        System.out.println("=====初始化动态数据源=====");
    }

}
